﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Root="clr-namespace:Elysium.Theme"
                    xmlns:Converters="clr-namespace:Elysium.Theme.Converters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Elysium.Theme;component/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
        
        <Setter Property="Background" Value="{StaticResource Transparent}"/>
        <Setter Property="BorderBrush" Value="{StaticResource ForegroundHighlight}"/>
        <Setter Property="BorderThickness" Value="{x:Static Root:Parameters.DefaultThickness}"/>
        
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding">
            <Setter.Value>
                <Thickness Left="{x:Static Root:Parameters.SemiboldPaddingValue}"
                           Top="0"
                           Right="{x:Static Root:Parameters.SemiboldPaddingValue}"
                           Bottom="0"/>
            </Setter.Value>
        </Setter>

        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Separator}">
                    <Border Background="{TemplateBinding Background}"
                            BorderThickness="0"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Line Stroke="{TemplateBinding BorderBrush}"
                              StrokeThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:ThicknessToDoubleConverter.Instance}}"
                              X1="0" Y1="0"
                              X2="1" Y2="0"
                              Stretch="Fill"
                              Margin="{TemplateBinding Padding}"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
    </Style>
    
    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                TextBlock.FontFamily="{TemplateBinding FontFamily}"
                TextBlock.FontSize="{TemplateBinding FontSize}"
                TextBlock.FontWeight="{TemplateBinding FontWeight}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid Margin="{TemplateBinding Padding}"
                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"
                                      SharedSizeGroup="ContextMenuIconSizeGroup"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"
                                      SharedSizeGroup="ContextMenuShortcutSizeGroup"/>
                </Grid.ColumnDefinitions>
                <Path x:Name="CheckBullet"
                      Grid.Column="0"
                      Fill="{StaticResource Transparent}"
                      Stroke="{StaticResource ForegroundLowlight}"
                      StrokeThickness="{x:Static Root:Parameters.BoldStrokeThickness}"
                      Stretch="Uniform"
                      Visibility="Collapsed"
                      HorizontalAlignment="Center" VerticalAlignment="Center"
                      Width="{TemplateBinding Root:Parameters.SubmenuItemBulletSize}" Height="{TemplateBinding Root:Parameters.SubmenuItemBulletSize}">
                    <Path.Data>
                        <GeometryGroup>
                            <LineGeometry StartPoint="0,3" EndPoint="4,8"/>
                            <LineGeometry StartPoint="4,8" EndPoint="8,0"/>
                        </GeometryGroup>
                    </Path.Data>
                </Path>
                <ContentPresenter x:Name="IconHost"
                                  Grid.Column="0"
                                  ContentSource="Icon"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center"
                                  MinWidth="16" MinHeight="16"/>
                <ContentPresenter x:Name="HeaderHost"
                                  Grid.Column="1"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center">
                    <ContentPresenter.Margin>
                        <Thickness Left="{x:Static Root:Parameters.BoldPaddingValue}"
                                   Top="0"
                                   Right="{x:Static Root:Parameters.BoldPaddingValue}"
                                   Bottom="0"/>
                    </ContentPresenter.Margin>
                </ContentPresenter>
                <TextBlock Grid.Column="2"
                           Text="{TemplateBinding InputGestureText}"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"/>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="IconHost" Property="Visibility" Value="Hidden"/>
            </Trigger>
            <Trigger Property="IsCheckable" Value="True">
                <Setter TargetName="IconHost" Property="Visibility" Value="Hidden"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="CheckBullet" Property="Visibility" Value="Visible"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="LayoutRoot"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                TextBlock.FontFamily="{TemplateBinding FontFamily}"
                TextBlock.FontSize="{TemplateBinding FontSize}"
                TextBlock.FontWeight="{TemplateBinding FontWeight}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid Margin="{TemplateBinding Padding}"
                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"
                                      SharedSizeGroup="ContextMenuIconSizeGroup"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="IconHost"
                                  Grid.Column="0"
                                  ContentSource="Icon"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center"
                                  MinWidth="16" MinHeight="16"/>
                <ContentPresenter x:Name="HeaderHost"
                                  Grid.Column="1"
                                  ContentSource="Header"
                                  RecognizesAccessKey="True"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Center">
                    <ContentPresenter.Margin>
                        <Thickness Left="{x:Static Root:Parameters.BoldPaddingValue}"
                                   Top="0"
                                   Right="{x:Static Root:Parameters.BoldPaddingValue}"
                                   Bottom="0"/>
                    </ContentPresenter.Margin>
                </ContentPresenter>
                <Polygon Grid.Column="2"
                         Fill="{StaticResource ForegroundLowlight}"
                         StrokeThickness="0"
                         Stretch="Uniform"
                         Margin="{TemplateBinding Root:Parameters.SubmenuHeaderArrowMargin}"
                         HorizontalAlignment="Right" VerticalAlignment="Center"
                         Width="{TemplateBinding Root:Parameters.SubmenuHeaderArrowSize}"
                         Height="{TemplateBinding Root:Parameters.SubmenuHeaderArrowSize}">
                    <Polygon.Points>
                        <PointCollection>
                            <Point X="0" Y="0"/>
                            <Point X="2" Y="2"/>
                            <Point X="0" Y="4"/>
                        </PointCollection>
                    </Polygon.Points>
                </Polygon>
                <Popup x:Name="PART_Popup"
                       Grid.IsSharedSizeScope="True"
                       Placement="Right"
                       PlacementTarget="{Binding ElementName=LayoutRoot}"
                       IsOpen="{TemplateBinding IsSubmenuOpen}"
                       Focusable="False">
                    <Border Background="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=Background}"
                            BorderBrush="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=BorderBrush}"
                            BorderThickness="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=BorderThickness}"
                            TextBlock.Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=Foreground}"
                            TextBlock.FontFamily="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontFamily}"
                            TextBlock.FontSize="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontSize}"
                            TextBlock.FontWeight="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontWeight}"
                            SnapsToDevicePixels="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=SnapsToDevicePixels}">
                        <StackPanel IsItemsHost="True"
                                    KeyboardNavigation.DirectionalNavigation="Cycle"/>
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="IconHost" Property="Visibility" Value="Hidden"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type MenuItem}">

        <Setter Property="Background" Value="{StaticResource Transparent}"/>
        <Setter Property="BorderBrush" Value="{StaticResource ForegroundMiddlelight}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=Foreground}"/>
        <Setter Property="FontFamily" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontFamily}"/>
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontSize}"/>
        <Setter Property="FontWeight" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=FontWeight}"/>
        
        <Setter Property="Focusable" Value="True"/>
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle}"/>

        <Setter Property="HorizontalContentAlignment" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=HorizontalContentAlignment}"/>
        <Setter Property="VerticalContentAlignment" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=VerticalContentAlignment}"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuBase}}, Path=Padding}"/>

        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>

        <Style.Triggers>
            
            <Trigger Property="Role" Value="TopLevelHeader">
                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelHeaderTemplateKey}}"/>
            </Trigger>
            <Trigger Property="Role" Value="TopLevelItem">
                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelItemTemplateKey}}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuHeader">
                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuHeaderTemplateKey}}"/>
            </Trigger>
            <Trigger Property="Role" Value="SubmenuItem">
                <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}"/>
            </Trigger>
            
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Role" Value="SubmenuItem"/>
                    <Condition Property="IsHighlighted" Value="True"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter Property="Background" Value="{StaticResource ForegroundMiddlelight}"/>
                    <Setter Property="Foreground" Value="{StaticResource ForegroundContrast}"/>
                </MultiTrigger.Setters>
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Role" Value="SubmenuHeader"/>
                    <Condition Property="IsHighlighted" Value="True"/>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter Property="Background" Value="{StaticResource ForegroundMiddlelight}"/>
                    <Setter Property="Foreground" Value="{StaticResource ForegroundContrast}"/>
                </MultiTrigger.Setters>
            </MultiTrigger>
            
        </Style.Triggers>
        
    </Style>
    
</ResourceDictionary>